<!DOCTYPE html>
<html>
<!--
Copyright 2009 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<head>
  <title>Google Earth API Samples - Setting Feature Opacity</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
  <!-- You should probably remove most of this extra cruft if you're copying
       this sample! -->
  <style type="text/css">@import "static/examples.css";</style>
  <style type="text/css">@import "static/prettify/prettify.css";</style>
  <script type="text/javascript" src="static/prettify/prettify.js"></script>
  
  <!-- Change the key below to your own Maps API key -->
  <script type="text/javascript" src="http://www.google.com/jsapi?hl=en&amp;key=ABQIAAAAwbkbZLyhsmTCWXbTcjbgbRSzHs7K5SvaUdm8ua-Xxy_-2dYwMxQMhnagaawTo7L1FE1-amhuQxIlXw"></script>
<!-- Very basic slider -->
<script src="static/simple-slider.js" type="text/javascript"></script>
<link href="static/simple-slider.css" type="text/css" rel="stylesheet"/>
  <script type="text/javascript">
  /* <![CDATA[ */
  var ge;
  var folder;
  var groundOverlay;
  var lineStringPlacemark;
  var pointPlacemark;
  
  google.load("earth", "1");

  function init() {
    google.earth.createInstance('map3d', initCB, failureCB);
    // make the slider for dragging the tour timeline
    var slider = new SimpleSlider(document.getElementById('slider-container'), {
      onSlide: function(pos) {
        if (folder)
          folder.setOpacity(pos);
      },
      max: 1.0,
      startPosition: 1.0,
      formatPosFn: function(pos) { return Math.floor(100 * pos) + '%'; }
    });
    
  }
  
  function initCB(instance) {
    ge = instance;
    ge.getWindow().setVisibility(true);
    
    // add a navigation control
    ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
    
    // add some layers
    ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
    ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);

    var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
    la.setRange(200000);
    la.setHeading(45);
    la.setTilt(45);
    ge.getView().setAbstractView(la);
    
    // Create a folder to contain various features.
    folder = ge.createFolder('');
    
    groundOverlay = ge.createGroundOverlay('');
    groundOverlay.setIcon(ge.createIcon(''))
    groundOverlay.getIcon().setHref("http://www.google.com/intl/en_ALL/images/logo.gif");
    groundOverlay.setLatLonBox(ge.createLatLonBox(''));
    
    var center = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
    var north = center.getLatitude() + .35;
    var south = center.getLatitude() - .35;
    var east = center.getLongitude() + .55;
    var west = center.getLongitude() - .55;
    var rotation = 0;
    var latLonBox = groundOverlay.getLatLonBox();
    latLonBox.setBox(north, south, east, west, rotation);
    folder.getFeatures().appendChild(groundOverlay);
    
    // Create a point placemark.
    pointPlacemark = ge.createPlacemark('');
    pointPlacemark.setName('Hello World');
    
    var style = ge.createStyle('');
    var icon = ge.createIcon('');
    icon.setHref('http://maps.google.com/mapfiles/kml/paddle/red-circle.png');
    style.getIconStyle().setIcon(icon);
    pointPlacemark.setStyleSelector(style);
    
    var point = ge.createPoint('');
    point.setLatitude(center.getLatitude());
    point.setLongitude(center.getLongitude());
    pointPlacemark.setGeometry(point);
    folder.getFeatures().appendChild(pointPlacemark);
    
    var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
    var lat = lookAt.getLatitude();
    var lng = lookAt.getLongitude();
    
    // Create a line string placemark
    lineStringPlacemark = ge.createPlacemark('');
    
    var style = ge.createStyle('');
    var lineStyle = style.getLineStyle();
    lineStyle.setWidth(10);
    lineStyle.getColor().set('ccff00ff');
    lineStringPlacemark.setStyleSelector(style);
    
    var lineString = ge.createLineString('');
    lineString.setTessellate(true);
    
    var coords = lineString.getCoordinates();
    coords.pushLatLngAlt(north + 0.1, east, 0);
    coords.pushLatLngAlt(north + 0.1, west, 0);
    coords.pushLatLngAlt(north + 0.35, west, 0);
    coords.pushLatLngAlt(north + 0.35, east, 0);
    lineStringPlacemark.setGeometry(lineString);
    folder.getFeatures().appendChild(lineStringPlacemark);
    
    // Finally, add the folder to the plugin.
    ge.getFeatures().appendChild(folder);
    
    document.getElementById('installed-plugin-version').innerHTML =
      ge.getPluginVersion().toString();
  }
  
  function failureCB(errorCode) {
  }
  
  /* ]]> */
  </script>
</head>
<body onload="if(window.prettyPrint)prettyPrint();init();">
  <h1>Google Earth API Samples - Setting Feature Opacity</h1>
  <dl>
            <dt>Last Modified:</dt><dd>08/25/2009</dd>
    <dt>Installed Plugin Version:</dt><dd id="installed-plugin-version">...</dd>
  </dl>
  <div style="clear: both;"></div>
  
  <div id="ui" style="position: relative;">
    <div id="map3d" style="border: 1px solid silver; width: 500px; height: 500px;"></div>

    <div id="extra-ui" style="position: absolute; left: 520px; top: 0;">
      <p style="color:red">WARNING: This feature is currently <a href="http://code.google.com/labs/faq.html#experimental">experimental</a>.</p>
      
      <div id="slider-container"></div>
      
      <h2>Relevant Resources:</h2>
      <ul>
<li><a href="http://code.google.com/apis/earth/documentation/reference/interface_kml_feature.html">KmlFeature Reference</a></li>
      </ul>
      <h2>Relevant Code Excerpt:</h2>      <pre class="prettyprint lang-html">&lt;!-- Very basic slider --&gt;
&lt;script src=&quot;static/simple-slider.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;link href=&quot;static/simple-slider.css&quot; type=&quot;text/css&quot; rel=&quot;stylesheet&quot;/&gt;</pre>      <pre class="prettyprint lang-js">var folder;
var groundOverlay;
var lineStringPlacemark;
var pointPlacemark;</pre>      <pre class="prettyprint lang-js">// make the slider for dragging the tour timeline
var slider = new SimpleSlider(document.getElementById('slider-container'), {
  onSlide: function(pos) {
    if (folder)
      folder.setOpacity(pos);
  },
  max: 1.0,
  startPosition: 1.0,
  formatPosFn: function(pos) { return Math.floor(100 * pos) + '%'; }
});</pre>      <pre class="prettyprint lang-js">var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
la.setRange(200000);
la.setHeading(45);
la.setTilt(45);
ge.getView().setAbstractView(la);

// Create a folder to contain various features.
folder = ge.createFolder('');

groundOverlay = ge.createGroundOverlay('');
groundOverlay.setIcon(ge.createIcon(''))
groundOverlay.getIcon().setHref(&quot;http://www.google.com/intl/en_ALL/images/logo.gif&quot;);
groundOverlay.setLatLonBox(ge.createLatLonBox(''));

var center = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
var north = center.getLatitude() + .35;
var south = center.getLatitude() - .35;
var east = center.getLongitude() + .55;
var west = center.getLongitude() - .55;
var rotation = 0;
var latLonBox = groundOverlay.getLatLonBox();
latLonBox.setBox(north, south, east, west, rotation);
folder.getFeatures().appendChild(groundOverlay);

// Create a point placemark.
pointPlacemark = ge.createPlacemark('');
pointPlacemark.setName('Hello World');

var style = ge.createStyle('');
var icon = ge.createIcon('');
icon.setHref('http://maps.google.com/mapfiles/kml/paddle/red-circle.png');
style.getIconStyle().setIcon(icon);
pointPlacemark.setStyleSelector(style);

var point = ge.createPoint('');
point.setLatitude(center.getLatitude());
point.setLongitude(center.getLongitude());
pointPlacemark.setGeometry(point);
folder.getFeatures().appendChild(pointPlacemark);

var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
var lat = lookAt.getLatitude();
var lng = lookAt.getLongitude();

// Create a line string placemark
lineStringPlacemark = ge.createPlacemark('');

var style = ge.createStyle('');
var lineStyle = style.getLineStyle();
lineStyle.setWidth(10);
lineStyle.getColor().set('ccff00ff');
lineStringPlacemark.setStyleSelector(style);

var lineString = ge.createLineString('');
lineString.setTessellate(true);

var coords = lineString.getCoordinates();
coords.pushLatLngAlt(north + 0.1, east, 0);
coords.pushLatLngAlt(north + 0.1, west, 0);
coords.pushLatLngAlt(north + 0.35, west, 0);
coords.pushLatLngAlt(north + 0.35, east, 0);
lineStringPlacemark.setGeometry(lineString);
folder.getFeatures().appendChild(lineStringPlacemark);

// Finally, add the folder to the plugin.
ge.getFeatures().appendChild(folder);</pre>    </div>
  </div>
</body>
</html>
